<? ob_start();?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>item</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
</head><body>


<script type="text/javascript"> 
function SetCwinHeight() { 
var iframeid = document.getElementById("maincontent1"); //iframe id 
iframeid.height = "10px";//先给一个够小的初值,然后再长高. 
if (document.getElementById) { 
if (iframeid && !window.opera) { 
if (iframeid.contentDocument && iframeid.contentDocument.body.offsetHeight) { 
iframeid.height = iframeid.contentDocument.body.offsetHeight; 
} else if (iframeid.Document && iframeid.Document.body.scrollHeight) { 
iframeid.height = iframeid.Document.body.scrollHeight; 
} 
} 
} 
} 

            function myfun()
            {
                var cha1;
                cha1=document.myform.quantity.value;
                if(cha1<=0)
                {
                    alert("数量不能为空");
                    return false;
                }
				var cha2;
				cha2=document.myform.price.value;
				if(cha2<=0)
				{
				    alert("价钱不能为空");
				    return false;
				}

			}
</script>  <?
include_once('conn.php');
include_once('include/func.php');
include_once('include/up_img_class.php');
include("admin_check.php");
$stock_detail = $db->select("SELECT * FROM `".tablepre."stock` where `sid` = '".$_GET[sid]."'");
if($_POST){
	//exit(floatval($_POST[price]));
	$db->INSERT("INSERT INTO `".tablepre."stock_item` (`sid`,`sale`,`quality1`,`quality2`,`quality3`,`quantity`,`price`,`model`,`unit`,`joindate`,`stock`,`batch`) VALUES ('".$_POST[sid]."','".floatval($_POST[sale])."','".htmlspecialchars($_POST[quality1])."','".htmlspecialchars($_POST[quality2])."','".htmlspecialchars($_POST[quality3])."','".floatval($_POST[quantity])."','".mround($_POST[price])."', '".htmlspecialchars($_POST[model])."', '".htmlspecialchars($_POST[unit])."', '".datetime."', '".htmlspecialchars($_POST[stock])."', '".htmlspecialchars($_POST[batch])."')");
	$db->UPDATE("UPDATE `".tablepre."stock` SET `onsale`='1' WHERE (`sid`='".$_POST[sid]."')");
	header("Location: $nowpage?action=1&sid=".$_POST[sid]);
	ob_end_flush();
	exit;	
	}
	//添加
	if(isset($_GET[delete])){
		//echo 'dfdf';
		$db->DELETE("DELETE FROM `".tablepre."stock_item` WHERE iid ='".$_GET[delete]."'");
		header("Location: $nowpage?action=1&sid=".$_GET[sid]);
		ob_end_flush();
		exit;	
		}
		//删除
if(isset($_GET[iframe])){
	echo '<iframe style="z-index: 1; visibility: inherit; width: 100%;" name="maincontent1" 
onload="Javascript:SetCwinHeight()" height="1" id="maincontent1" src="admin_item.php?action=1&sid='.$_GET[sid].'" 
marginwidth="0" marginheight="0" frameborder="0" scrolling="no"></iframe> 
	';
	}
if($_GET[action]==1){
?>
<style type="text/css">
body,td,th {
	font-size: 12px;
}
body {
 margin: 0px;
}
img{
	border:0px;}
</style>
<img src="images/ttfjpg.php?t=商品详细&bg=titlebg2.jpg&z=18&x=5&y=22&r=0&b=0&g=0"  />
<table width="850" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td valign="top">标题：<? echo $stock_detail[0][1]; ?></td>
    <td rowspan="3" valign="top"><a href="<? echo pic_return(attachment($con0=1,$con1=$stock_detail[0][0],$con2='pic'));  ?>" target="_blank"><img src="<? echo pic_return(attachment($con0=1,$con1=$stock_detail[0][0],$con2='pic'));  ?>"  height="100" /></a></td>
  </tr>
  <tr>
    <td valign="top">型号：<? echo attachment($con0=1,$con1=$stock_detail[0][0],$con2='model');  ?></td>
  </tr>
  <tr>
    <td valign="top">网址：<? echo attachment($con0=1,$con1=$stock_detail[0][0],$con2='url')<>null?'<a href="'.attachment($con0=1,$con1=$stock_detail[0][0],$con2='url').'" target="_blank">'.MEMBER_WEB.'</a>':'';  ?></td>
  </tr>

</table>
<img src="images/ttfjpg.php?t=添加新库存&bg=titlebg2.jpg&z=18&x=5&y=22&r=0&b=0&g=0"  />

<form name="myform" method="post" onSubmit="return myfun()">
<font color="red">不要输入空格以及特殊字符[如 ' &quot; ` ,]，避免出错。</font>
<table width="905" border="0" cellspacing="2" cellpadding="2" style="border:#CCC 1px solid; margin:2px 2px 10px 2px;">
    <tr style="padding:3px; background:#EFEFEF;">
    <td>批次：</td>
      <td>型号：</td>
      <td>上架：</td>
      <td>颜色：</td>
      <td>尺寸：</td>
      <td>材质：</td>
      <td>储存仓库：</td>
      <td>数量：</td>
      <td>售价[单价]：</td>
      <td>单位：</td>
          </tr>
    <tr style="padding:3px;">
    <td><input type="text" name="batch" size="8"></td>
      <td><input type="text" name="model" size="8"><input name="sid" type="hidden" value="<? echo $_GET[sid]?>"></td>
      <td><select name="sale">
        <option value="1">上架</option>
        <option value="0">下架</option>
      </select></td>
      
          <td><input type="text" name="quality1" size="8"></td>
      <td><input type="text" name="quality2" size="8"></td>
      <td><input type="text" name="quality3" size="8"></td>
      <td><select name="stock"><? echo stock_check(parameters(14));?></select></td>
      <td><input type="text" name="quantity" size="8" onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"></td>
      <td><input type="text" name="price" size="8" onKeyPress="if (event.keyCode!=46 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false"></td>
      <td><input type="text" name="unit" size="8" value="<? echo parameters(24);?>"></td>

     </tr>
</table>
<input type="submit" name="button" value="添加" style=" padding:5px; border: #333 solid 1px; font-size:16px;">
</form>
<? } ?>
<script src="js/jquery_ajax_item_control.js" type="text/javascript" language="javascript" charset="UTF-8"></script>

<?
$is_arr = $db->select("SELECT sid FROM `".tablepre."stock_item` where `sid` = '".$_GET[sid]."' limit 1");
if($is_arr[0][0]==TRUE && $_GET[action]==1){
		count_item_quantity(1,$_GET[sid])

	?>
    <img src="images/ttfjpg.php?t=现有库存&bg=titlebg2.jpg&z=18&x=5&y=22&r=0&b=0&g=0" style="float:left;"  /><div style="float:right;"><div id="show_ch"></div></div><div style="clear:both; height:0px; overflow:hidden;"></div>
    <div id="here">
    
    <table width="905" border="0" cellspacing="2" cellpadding="2" style="border:#CCC 1px solid; margin:2px 2px 10px 2px;">
    <tr style="padding:3px; background:#EFEFEF;">
    <td>批次：</td>
      <td>型号：</td>
      <td>上架：</td>
      <td>颜色：</td>
      <td>尺寸：</td>
      <td>材质：</td>
      <td>储存仓库：</td>
      <td>数量：</td>
      <td>售价[单价]：</td>
      <td>单位：</td>
      <td>&nbsp;</td>
        </tr>
          <? $stock_item = $db->select("SELECT * FROM `".tablepre."stock_item` where `sid` = '".$_GET[sid]."'");
		  for($i=0;$i<count($stock_item);$i++) {
		  ?>
    <tr style="padding:3px;">
    <td><input name="batch" id="<? echo $stock_item[$i][0]; ?>" type="text" value="<? echo $stock_item[$i][15]; ?>" size="8" ></td>
      <td><input name="model" id="<? echo $stock_item[$i][0]; ?>" type="text" value="<? echo $stock_item[$i][8]; ?>" size="8" ></td>
      <td><select name="sale" id="<? echo $stock_item[$i][0]; ?>" class="select" >
      <? echo $stock_item[$i][9]==1?'<option value="1">上架</option>':'<option value="0">下架</option>';?>
        <option value="1">上架</option>
        <option value="0">下架</option>
      </select></td>
          <td><input type="text" name="quality1" id="<? echo $stock_item[$i][0]; ?>"  size="8" value="<? echo $stock_item[$i][3]; ?>" ></td>
      <td><input type="text" name="quality2" id="<? echo $stock_item[$i][0]; ?>" size="8" value="<? echo $stock_item[$i][4]; ?>" ></td>
      <td><input type="text" name="quality3" id="<? echo $stock_item[$i][0]; ?>" size="8" value="<? echo $stock_item[$i][5]; ?>" ></td>
      <td><select name="stock" id="<? echo $stock_item[$i][0]; ?>" class="select" ><? echo stock_check(parameters(14),$stock_item[$i][13]);?></select></td>
      <td><input type="text" name="quantity" id="<? echo $stock_item[$i][0]; ?>,<? echo $_GET[sid];?>" size="8" value="<? echo $stock_item[$i][6]; ?>" onkeyup="value=value.replace(/[^\d]/g,''),ajax_admin_ch_item(<? echo $stock_item[$i][0]; ?>,'quantity',<? echo $_GET[sid];?>)"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" onkeydown="ajax_admin_ch_item(<? echo $stock_item[$i][0]; ?>,'quantity',<? echo $_GET[sid];?>)" ></td>
      <td><input type="text" name="price" id="<? echo $stock_item[$i][0]; ?>" size="8" value="<? echo mround($stock_item[$i][7]); ?>" onKeyPress="if (event.keyCode!=46 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false" ></td>
      <td><input type="text" name="unit" id="<? echo $stock_item[$i][0]; ?>" size="8" value="<? echo $stock_item[$i][12]; ?>"></td>
      <td><a href="?delete=<? echo $stock_item[$i][0]; ?>&sid=<? echo $_GET[sid]; ?>" onclick="return confirm('注意！删除后不能恢复！确定删除？')">删除</a></td>
    </tr>
    <? } ?>
</table></div>
	<?
	}

?></body>
</html>